实验环境
- 需要使用python3,2不可以。
- Fedora30或centos7
参考策略安装过程
- https://github.com/TresysTechnology/refpolicy/wiki
- 大体是按照上面的wiki,但是wiki年久失修,有一些错误。
1 | 可以在主目录下 |
构建和安装头文件
1 | # cd /etc/selinux/refpolicy/src/policy |
编写自己的策略模块
1 | cd ~ |
↓myapp.te1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17policy_module(myapp,1.0)
# Private type declarations
type myapp_t;
type myapp_exec_t;
type myapp_log_t;
type myapp_tmp_t;
domain_type(myapp_t)
domain_entry_file(myapp_t, myapp_exec_t)
logging_log_file(myapp_log_t)
files_tmp_file(myapp_tmp_t)
allow myapp_t myapp_log_t:file append_file_perms;
allow myapp_t myapp_tmp_t:file manage_file_perms;
files_tmp_filetrans(myapp_t,myapp_tmp_t,file)
↓myapp.fc1
/usr/bin/myapp -- gen_context(system_u:object_r:myapp_exec_t,s0)
↓myapp.if1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53## <summary>Myapp example policy</summary>
## <desc>
## <p>
## More descriptive text about myapp. The desc
## tag can also use p, ul, and ol
## html tags for formatting.
## </p>
## <p>
## This policy supports the following myapp features:
## <ul>
## <li>Feature A</li>
## <li>Feature B</li>
## <li>Feature C</li>
## </ul>
## </p>
## </desc>
########################################
## <summary>
## Execute a domain transition to run myapp.
## </summary>
## <param name="domain">
## <summary>
## Domain allowed to transition.
## </summary>
## </param>
interface(`myapp_domtrans',\`
gen_requires(`
type myapp_t, myapp_exec_t;
')
domtrans_pattern($1,myapp_exec_t,myapp_t)
')
########################################
## <summary>
## Read myapp log files.
## </summary>
## <param name="domain">
## <summary>
## Domain allowed to read the log files.
## </summary>
## </param>
interface(`myapp_read_log',\`
gen_requires(`
type myapp_log_t;
')
logging_search_logs($1)
allow $1 myapp_log_t:file read_file_perms;
')
↓Makefile1
2
3
4
5
6
7AWK ?= gawk
NAME ?= $(shell $(AWK) -F= '/^SELINUXTYPE/{ print $$2 }' /etc/selinux/config)
SHAREDIR ?= /usr/share/selinux
HEADERDIR := $(SHAREDIR)/$(NAME)/include
include $(HEADERDIR)/Makefile
1 | cd ~/myapp |
错误记录
- 修改selinux导致无法开机
1
2
3在Grub启动菜单上按e进入编辑模式,在启动项
“kernel /vmlinuz-2.6.23.1-42.fc8 ro root=/dev/vogroup00/logvol00 rhgb quiet”
后面加上 enforcing=0 ,然后启动即可。